package session08.practise;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ShowImageFrame extends JFrame {

    private Container contentP;
    private JButton preBtn;
    private JButton nextBtn;
    private PicturePanel picP;

    public ShowImageFrame(){
        this.setSize(500,500);
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setResizable(false);
        this.addContent();
        this.setVisible(true);
    }

    private void addContent() {
        this.contentP = this.getContentPane();
        this.contentP.setLayout(null);

        this.preBtn = new JButton("<<");
        this.preBtn.setBounds(10,200,50,80);
        this.contentP.add(this.preBtn);
        this.preBtn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                CardLayout cardLayout = (CardLayout) ShowImageFrame.this.picP.getLayout();
                cardLayout.previous(ShowImageFrame.this.picP);
            }
        });

        this.nextBtn = new JButton(">>");
        this.nextBtn.setBounds(440,200,50,80);
        this.contentP.add(this.nextBtn);
        this.nextBtn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                CardLayout cardLayout = (CardLayout) ShowImageFrame.this.picP.getLayout();
                cardLayout.next(ShowImageFrame.this.picP);
            }
        });

        this.picP = new PicturePanel();
        this.picP.setBounds(70,20,360,420);
        this.contentP.add(this.picP);
    }

}
